<div class="mod">
    <div id="updatecomment">
    <div id="cc.<?php echo $comment->id; ?>">
        <div>
        <div id="img_<?php echo $comment->id; ?>"><img src="<?php echo Yii::app()->request->baseUrl; ?>/themes/bjoco/images/soc_01.png ?>" height="32" width="32"/></div>
        <?php
            $names= $comment->user->name;
            echo CHtml::link("$names",array('/user/default/index','id'=>Yii::app()->user->id));
        ?> bình luận:
        <form name="edit_comment" id="editco.<?php echo $comment->id; ?>" value="<?php echo $comment->id; ?>">
            <div id="id_<?php echo $comment->id; ?>">
            <input class="e_comment" name="edit_<?php echo $comment->id; ?>" id="c.<?php echo $comment->id; ?>" type="text" 
                value="<?php echo nl2br(CHtml::encode($comment->content)); ?>" readonly="true"/>
            </div>
            <input type="hidden" name="edithidden[]" value="<?php echo $comment->id; ?>"/>
        </form>
        </div>
        <div class="time">
        <?php 
            $date = new DateTime($comment->timepost);
            echo date_format($date, 'F j, Y \a\t h:i a');
        ?>
        </div>
        
        <input type='button' value='edit' class='editcomment' id='<?php echo $comment->id; ?>'>
        <input class='delete' type='button' value='delete' id='<?php echo $comment->id; ?>'>
        <!-- <input type="button" id="reply" value="reply"><br/> -->
        <!-- <textarea class="reply"></textarea> -->
    </div><!-- comment -->
    </div>
</div>

<script type="text/javascript">
    $(function() {
        $(".editcomment").click(function() {
          var commentContainer = $(this).parent();
          var eid= $(this).attr("id");
          //var econtent= $(this).attr("")
          //var string= 'eid='+eid;
          var string= $('form').serialize();
          $("#"+eid).prop('value', 'Save');
          if (document.getElementById("c."+eid).readOnly == false) {
            $("#"+eid).prop('value', 'edit');
            document.getElementById('c.'+eid).readOnly = true;
            $.ajax({
              type: "POST",
              url: "<?php echo Yii::app()->createUrl('/comment/save');?>",
              data: string,
              //cache: false,
              success: function(){
                $('#c.'+eid).html(data);
              },
            });
          } else {
            document.getElementById("c."+eid).readOnly = false;
          }
        });
    });
</script>

<script type="text/javascript">
  $('#reply').click(function(){
    $(this).parent().append($('<textarea>').attr('class','reply'));
  });
</script>

<script type="text/javascript">
    $(function() {
        $(".delete").click(function() {
            var commentContainer = $(this).parent();
            var id = $(this).attr("id");
            var string = 'pid='+ id ;
                
            $.ajax({
               type: "POST",
               url: "<?php echo Yii::app()->createUrl('/comment/deleteone');?>",
               data: string,
               cache: false,
               success: function(){
                commentContainer.slideUp('slow', function() {$(this).remove();});
              }
             });
            return false;
        });
    });
    // 2 cách đều đúng
    // function delete_(pid){
    //     $.ajax({
    //        type: "POST",
    //        url: "<?php echo Yii::app()->createUrl('/comment/deleteone');?>",
    //        data: {pid: pid},
    //        cache: false,
    //        success: function(){
    //             $(".editcomment.").remove();
    //     },
    // });
    // };
</script>

